//
//  CollectionViewCell.m
//  Linkage
//
//  Created by LeeJay on 16/8/22.
//  Copyright © 2016年 LeeJay. All rights reserved.
//  代码下载地址https://github.com/leejayID/Linkage

#import "CollectionCategoryModel.h"
#import "CollectionViewCell.h"
@interface CollectionViewCell ()
@property (nonatomic, strong) UIImageView *imageV;
@property (nonatomic, strong) UILabel *name;
@end
@implementation CollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        self.imageV = [[UIImageView alloc] initWithFrame:CGRectMake((self.frame.size.width-60)/2, 28, 60, 60)];
        self.imageV.contentMode = UIViewContentModeScaleAspectFit;
        
        [self.contentView addSubview:self.imageV];

        self.name = [[UILabel alloc] initWithFrame:CGRectMake(0, self.imageV.frame.size.height+self.imageV.frame.origin.y+9, self.frame.size.width, 20)];
        self.name.font = [UIFont systemFontOfSize:13];
        self.name.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:self.name];
    }
    return self;
}

-(void)setModel:(NewEquipment *)model
{
    _model = model;
    self.name.text = model.name;
    self.imageV.image = [self setImageByEquipmentName:model];
}

- (UIImage *)setImageByEquipmentName:(NewEquipment *)equipment{
    if (!equipment)
        return nil;

    if([equipment.type isEqualToString:@"1"])
    {
        if ([equipment.state isEqualToString:@"1"]) {
            return [UIImage imageNamed:@"icon_dengguan_on"];
        } else {
            return [UIImage imageNamed:@"icon_light"];
        }
    }
    else if([equipment.type isEqualToString:@"2"])
    {
        if ([equipment.state isEqualToString:@"1"]) {
            return [UIImage imageNamed:@"icon_kongtiao_on"];
        } else {
            return [UIImage imageNamed:@"icon_kongtiao_off"];
        }
    }
    else if([equipment.type isEqualToString:@"3"])
    {
        if ([equipment.state isEqualToString:@"1"]) {
            return [UIImage imageNamed:@"icon_tv_on"];
        } else {
            return [UIImage imageNamed:@"icon_tv"];
        }
    }
    else if([equipment.type isEqualToString:@"4"])
    {
        if ([equipment.state isEqualToString:@"1"]) {
            return [UIImage imageNamed:@"icon_dvd_on"];
        } else {
            return [UIImage imageNamed:@"icon_dvd"];
        }
    }
    else if([equipment.type isEqualToString:@"5"])
    {
        if ([equipment.state isEqualToString:@"1"]) {
            return [UIImage imageNamed:@"icon_chuanglian_on"];
        } else {
            return [UIImage imageNamed:@"icon_chuanglian"];
        }
    }
    else if([equipment.type isEqualToString:@"8"])
    {
        if ([equipment.state isEqualToString:@"1"]) {
            return [UIImage imageNamed:@"icon_qita_on"];
        } else {
            return [UIImage imageNamed:@"icon_qita_off"];
        }
    }
    else if([equipment.type isEqualToString:@"9"])
    {
        if ([equipment.state isEqualToString:@"1"]) {
            return [UIImage imageNamed:@"icon_anfang_on"];
        } else {
            return [UIImage imageNamed:@"icon_anfang"];
        }
    }
    else if([equipment.type isEqualToString:@"10"])
    {
        if ([equipment.state isEqualToString:@"1"]) {
            return [UIImage imageNamed:@"icon_music_on"];
        } else {
            return [UIImage imageNamed:@"icon_music_off"];
        }
    }else {
        if ([equipment.state isEqualToString:@"1"]) {
            return [UIImage imageNamed:@"icon_qita_on"];
        } else {
            return [UIImage imageNamed:@"icon_qita_off"];
        }
    }
    return nil;
    
}

- (void)click
{
    if ([_delegate respondsToSelector:@selector(clicks)]) {
        [self.delegate clicks];
    }
}

@end
